package com.hns.can.energy.service;
import java.util.List;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.energy.entity.BsDayEneInfoEntity;
import com.hns.can.energy.vo.EnergyStatisticsVo;
import com.hns.can.energy.vo.ParamVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.hns.tool.pub.PubUtil;
/**
 * 能耗表统计信息service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class EnergyStatisticsService extends CommonService {
    
    @Autowired
    private FillCodeDscValue codeDscValue;

    /**
     *  查询
     * @param conditionVo
     * @return
     * @throws Exception
     */
    @LeftOrgAnnotation()
    @Transactional
    public Pagination searchEnergyStatistics(ParamVo paramVo) throws Exception {
        Pagination page = this.myBatisPage("energyStatistics.searchEnergyStatisticsCnt", "energyStatistics.searchEnergyStatisticsData", paramVo,EnergyStatisticsVo.class);
        return page;
    }

    /**
     * 导出
     * @param conditionVo
     * @return
     * @throws Exception
     */
    @LeftOrgAnnotation()
    @Transactional
    public List<BsDayEneInfoEntity> exportEnergyStatistics(ParamVo vo) throws Exception {
        List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("energyStatistics.searchEnergyStatisticsData", vo), EnergyStatisticsVo.class);
        return list;
    }
    
    @LeftOrgAnnotation()
    @Transactional
    public List getCarEnergyDetail(CommonParamsVo vo) throws Exception {
            List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("energyStatistics.getCarEnergyDetail", vo), BsDayEneInfoEntity.class);
            //数据填充
            if(list!=null){
            	for (int j = 1; j<list.size(); j++){
                	BsDayEneInfoEntity entity0=(BsDayEneInfoEntity)list.get(j-1);
                	BsDayEneInfoEntity entity1=(BsDayEneInfoEntity)list.get(j);
                	if((entity1.getTotalMile()==null )||(entity1.getTotalMile()).doubleValue()==0){
                		entity1.setTotalMile(entity0.getTotalMile());
                	}
                	if((entity1.getTotalEnerCons()==null )||(entity1.getTotalEnerCons()).doubleValue()==0){
                		entity1.setTotalEnerCons(entity0.getTotalEnerCons());
                	}
                	if((entity1.getTotalOprtDura()==null )||(entity1.getTotalOprtDura()).doubleValue()==0){
                		entity1.setTotalOprtDura(entity0.getTotalOprtDura());
                	}
    			}
            }
            
            return list;
        }
}
